<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="sec"
	uri="http://www.springframework.org/security/tags"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="huoyun" uri="/huoyun"%>
<div>
	<table id="J_BoughtTable" class="bought-table">
		<colgroup>
			<col class="selector">
			<col class="baobei">
			<col class="after-service">
			<col class="price">
			<col class="trade-status">
			<col class="operate">
			<col class="other">
		</colgroup>
		<thead>
			<tr class="col-name">
				<th></th>
				<th class="baobei">
					车辆
				</th>
				<th class="after-service">
					货物
				</th>
				<th class="price">
					运费(元)
				</th>
				<th class="trade-status">
					状态
				</th>
				<!--<th class="amount">
					实付款(元)
				</th>  -->
				<th class="remark">
					交易操作
				</th>
				<th class="other">
					其它操作
				</th>
			</tr>
			<tr class="sep-row">
				<td colspan="7"></td>
			</tr>
			<tr class="toolbar skin-gray">
				<td colspan="3">
					<label>
						<input type="checkbox" name="allSelector" id="order_allSelector" onclick="allSelectOrder(this)" class="all-selector">全选
					</label>
					<a id="J_CombinPay" class="J_MakePoint toolbtn" href="#">合并付款</a>
				</td>
				<td colspan="4" class="last-col">
				<s:if test="orderPage != null && orderPage.totalPage > 1">
				    <s:url var="queryOrderUrl" action="orderList.action" namespace="/order"><s:param name="status"><s:property value="status"/></s:param></s:url>
					<huoyun:page pageNo="${orderPage.pageNo}" url="${queryOrderUrl}" totalPage="${orderPage.totalPage}" totalRecord="${orderPage.totalRecord}" isAjax="true" ajaxDiv="tabs-1"></huoyun:page>
				</s:if>
				</td>
			</tr>
		</thead>
		<s:if test="orderPage">
		<s:iterator var="orderObj" value="orderPage.objectList">
		<tbody id="content_<s:property value="#orderObj.id"/>" class="<s:if test="#orderObj.status > 3">close-order</s:if>">
			<tr class="sep-row">
				<td colspan="7"></td>
			</tr>
			<tr class="order-hd">
				<td colspan="7">
					<span class="no"> 
						<label>
						<input type="checkbox" <s:if test="#orderObj.status > 3">disabled="disabled"</s:if> value="<s:property value="#orderObj.orderId"/>" name="orderIds"
									id="orderId_<s:property value="#orderObj.id"/>" class="selector">
						 订单编号：<span class="order-num"><a href="${pageContext.request.contextPath}/order/viewOrder.action?orderId=<s:property value='#orderObj.id'/>"><s:property value="#orderObj.orderId"/></a></span>
						</label>
					</span>
					<span class="deal-time">成交时间：<huoyun:dateFormat date="${orderObj.addTime}" dateFormat="yyyy-MM-dd HH:mm:ss"/></span>
				</td>
			</tr>
			<tr class="order-bd last" id="">
				<td colspan="2" class="baobei">
					<a class="pic s50" href="" title="查看车辆详情" target="_blank"> 
					<img src="" alt="查看车辆详情"> </a>
					<div class="desc">
						<a href="" target="_blank" class="baobei-name"> 
						<s:property value="#orderObj.carNumber"/>
						</a>
						<div class="spec">
							<span>xxxxx</span>
						</div>
					</div>
				</td>
				<td class="after-service">
					<s:property value="#orderObj.cargisTitle"/>
				</td>
				<td title="<s:property value="#orderObj.price"/>" class="price">
					<s:property value="#orderObj.price"/>
				</td>
				<s:if test="#orderObj.status == 1">
					<td rowspan="1" id="order_status_<s:property value="#orderObj.id"/>" class="trade-status">
						<span>待付款</span>
						<a class="J_MakePoint  status" href="${pageContext.request.contextPath}/order/viewOrder.action?orderId=<s:property value='#orderObj.id'/>">查看详情</a>
					</td>
					<td rowspan="1" id="order_operate_<s:property value="#orderObj.id"/>" class="operate">
						<sec:authorize access="hasRole('ROLE_USER')"><a href="javascript:void(0);" onclick="payBond(<s:property value='#orderObj.id'/>)">付款</a></sec:authorize>
						<sec:authorize access="hasRole('ROLE_DRIVER')"><a href="">提醒货主</a></sec:authorize>
						<a href="javascript:void(0);" onclick="cancelOrder('<s:property value="#orderObj.id"/>')">取消订单</a>
					</td>
				</s:if>
				<s:elseif test="#orderObj.status == 2">
					<td rowspan="1" id="order_status_<s:property value="#orderObj.id"/>" class="trade-status">
						<span>待确认</span>
						<a class="J_MakePoint  status" href="${pageContext.request.contextPath}/order/viewOrder.action?orderId=<s:property value='#orderObj.id'/>">查看详情</a>
					</td>
					<td rowspan="1" id="order_operate_<s:property value="#orderObj.id"/>" class="operate">
						<sec:authorize access="hasRole('ROLE_USER')"><a href="javascript:void(0);" onclick="loadCargos(<s:property value='#orderObj.id'/>)">确认交易</a></sec:authorize>
					</td>
				</s:elseif>
				<s:elseif test="#orderObj.status == 3">
					<td rowspan="1" id="order_status_<s:property value="#orderObj.id"/>" class="trade-status">
						<span>待评价</span>
						<a class="J_MakePoint  status" href="${pageContext.request.contextPath}/order/viewOrder.action?orderId=<s:property value='#orderObj.id'/>">查看详情</a>
					</td>
					<td rowspan="1" id="order_operate_<s:property value="#orderObj.id"/>" class="operate">
						<sec:authorize access="hasRole('ROLE_USER')"><a href="${pageContext.request.contextPath}/rate/preRate.action?orderId=<s:property value='#orderObj.id'/>">评价</a></sec:authorize>
					</td>
				</s:elseif>
				<s:elseif test="#orderObj.status == 4">
					<td rowspan="1" id="order_status_<s:property value="#orderObj.id"/>" class="trade-status">
						<span>交易完成</span>
						<a class="J_MakePoint  status" href="${pageContext.request.contextPath}/order/viewOrder.action?orderId=<s:property value='#orderObj.id'/>">查看详情</a>
					</td>
					<td rowspan="1" id="order_operate_<s:property value="#orderObj.id"/>" class="operate">
						
					</td>
				</s:elseif>
				<s:else>
					<td rowspan="1" id="order_status_<s:property value="#orderObj.id"/>" class="trade-status">
					<span>交易关闭</span>
					<a class="J_MakePoint  status" href="${pageContext.request.contextPath}/order/viewOrder.action?orderId=<s:property value='#orderObj.id'/>">查看详情</a>
					</td>
					<td rowspan="1" id="order_operate_<s:property value="#orderObj.id"/>" class="operate"></td>
				</s:else>
				<td rowspan="1" class="other">
					<a href="javascript:void(0)" onclick="deleteOrder('<s:property value="#orderObj.id"/>')" class="J_MakePoint">删除</a>
				</td>
			</tr>

		</tbody>
		</s:iterator>
		</s:if>
		<tfoot>
					<tr class="sep-row"><td colspan="7"></td></tr>
					<tr class="toolbar skin-gray">
			<td colspan="3">
			    <label><input type="checkbox" name="allSelector" id="order_allSelector2" onclick="allSelectOrder(this)" class="all-selector">全选</label>
				<a class="J_MakePoint toolbtn" href="javascript:void(0)" id="J_CombinPay2">合并付款</a>
		    </td>					    		
                                    <td colspan="4" class="page-nav-cell">
                            <s:if test="orderPage != null && orderPage.totalPage > 1">
			    <s:url var="queryOrderUrl" action="orderList.action" namespace="/order"></s:url>
				<huoyun:page pageNo="${orderPage.pageNo}" url="${queryOrderUrl}" totalPage="${orderPage.totalPage}" totalRecord="${orderPage.totalRecord}" isAjax="true" ajaxDiv="tabs-1"></huoyun:page>
			</s:if>
			</td>
			</tr>
		</tfoot>
	</table>
	<script type="text/javascript">
	
	$(function(){
		
		$("input[name='orderIds'][type='checkbox']:enabled").bind("click",function(){
			
			$("input[name='allSelector'][type='checkbox']").prop("checked", checkSelectOrders());
		});
	});
	
	function checkSelectOrders()
	{
		var selectOrders = $("input[name='orderIds'][type='checkbox']:enabled")
		
		if(selectOrders.length > 0)
		{
			for(var i = 0; i < selectOrders.length; i++)
			{
				if($(selectOrders[i]).is(":checked") == false)
				{
					return false;
				}
			}
		}
		
		return true;
	}
	function allSelectOrder(obj)
	{
		$("input[name='orderIds'][type='checkbox']:enabled").prop("checked", $(obj).is(":checked"));
		
		$("input[name='allSelector'][type='checkbox']").prop("checked", $(obj).is(":checked"));
	}
	
	function deleteOrder(orderId)
	{
	    if(confirm("您确认要删除该订单？"))
	    {
		    $.ajax({
	            type: "POST",
	            url: "${pageContext.request.contextPath}/orderOperate/deleteOrder.action",
	            data: {"orderId" : orderId},
	            dataType: "json",
	            success: function(data) 
	            {
	           		alert(data.result.message);
	           		
	           	    if(data.result.result == "success")
	           	    {
	           	    	$("#content_" + orderId).remove();
	           	    }
			   },
			   error: function()
			   {
			        alert("系统忙，请稍后再试。");
			   }
	    	});
	    }
	}
	
	function cancelOrder(orderId)
	{
		if(confirm("您确认要取消该订单？"))
	    {
			$.ajax({
	            type: "POST",
	            url: "${pageContext.request.contextPath}/orderOperate/cancelOrder.action",
	            data: {"orderId" : orderId},
	            dataType: "json",
	            success: function(data) 
	            {
	           		alert(data.result.message);
	           		
	            	if(data.result.result == "success")
	            	{
	            		$("#order_status_" + orderId).html("<span>交易关闭</span><a class='J_MakePoint  status' href='${pageContext.request.contextPath}/order/viewOrder.action?orderId="+orderId+"'>查看详情</a>");
	            		$("#order_operate_" + orderId).html("");
	            		$("#content_" + orderId).addClass("close-order");
	            		$("#orderId_" + orderId).attr("disabled", true);
	            	}
			   },
			   error: function()
			   {
			        alert("系统忙，请稍后再试。");
			   }
	    	});
    	}
	}
	
	</script>
</div>
					